from django.db import models

# Create your models here.
from type.models import ProductTypeModel


class ProductModel(models.Model):
    title = models.CharField(max_length=200, verbose_name='产品标题', null=True, blank=True)
    title_en = models.CharField(max_length=200, verbose_name='英文标题', null=True, blank=True)
    first_image = models.ImageField(upload_to="first_image", blank=True, verbose_name="产品首图")
    type = models.ForeignKey(to=ProductTypeModel, on_delete=models.SET_NULL, blank=True, null=True,
                             verbose_name='产品类型')
    desc = models.TextField(verbose_name='产品描述', null=True, blank=True)
    desc_en = models.TextField(verbose_name='英文描述', null=True, blank=True)
    create_time = models.DateTimeField(auto_now=True, blank=True, null=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='最后修改时间', blank=True, null=True)

    def __str__(self):
        return self.title

    class Meta:
        db_table = 't_product'
        verbose_name = '产品'
        verbose_name_plural = '产品'


class ImagesModel(models.Model):
    image = models.ImageField(upload_to="photo", verbose_name="产品图片")
    product = models.ForeignKey(to=ProductModel, on_delete=models.CASCADE, blank=True, null=True,
                                related_name='image', verbose_name='产品')
    create_time = models.DateTimeField(auto_now=True, blank=True, null=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='最后修改时间', blank=True, null=True)

    def __str__(self):
        return ""

    class Meta:
        db_table = 't_product_images'
        verbose_name = '产品图片'
        verbose_name_plural = '产品图片'


class ProblemModel(models.Model):
    title = models.CharField(max_length=500, verbose_name='产品问题')
    title_en = models.CharField(max_length=500, verbose_name='英文问题')
    product = models.ForeignKey(to=ProductModel, on_delete=models.CASCADE, blank=True, null=True,
                                related_name='problem',
                                verbose_name='产品')
    create_time = models.DateTimeField(auto_now=True, blank=True, null=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='最后修改时间', blank=True, null=True)

    def __str__(self):
        return self.title

    class Meta:
        db_table = 't_product_problem'
        verbose_name = '产品问题'
        verbose_name_plural = '产品问题'


class AnswerModel(models.Model):
    ans = models.CharField(max_length=500, blank=True, verbose_name='答案')
    ans_en = models.CharField(max_length=500, blank=True, verbose_name='英文答案')
    problem = models.ForeignKey(to=ProblemModel, on_delete=models.CASCADE, blank=True, null=True,
                                related_name='answer', verbose_name='问题')
    create_time = models.DateTimeField(auto_now=True, blank=True, null=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now_add=True, verbose_name='最后修改时间', blank=True, null=True)

    def __str__(self):
        return self.ans

    class Meta:
        db_table = 'product_answer'
        verbose_name = '答案'
        verbose_name_plural = '答案'
